The following example demonstrates how to alternate the appearance of data row styles using the IndexToOddConverter.
XAML |
Copy Code |
---|---|
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"> <Grid.Resources> <xcdg:IndexToOddConverter x:Key="rowIndexConverter"/> <Style TargetType="{x:Type xcdg:DataRow}"> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(xcdg:DataGridVirtualizingPanel.ItemIndex), Converter={StaticResource rowIndexConverter}}" Value="True"> <Setter Property="Background"> <Setter.Value> <SolidColorBrush Color="LightGray" Opacity="0.1"/> </Setter.Value> </Setter> </DataTrigger> </Style.Triggers> </Style> <xcdg:DataGridCollectionViewSource x:Key="cvs_orders" Source="{Binding Source={x:Static Application.Current}, Path=Orders}"/> </Grid.Resources> <xcdg:DataGridControl x:Name="OrdersGrid" ItemsSource="{Binding Source={StaticResource cvs_orders}}"> </xcdg:DataGridControl> </Grid> |
As of version 3.1, it is also possible to enable alternate row styles, by setting the IsAlternatingRowStyleEnabled property, which is defined in the TableView class, to true.
XAML |
Copy Code |
---|---|
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"> <Grid.Resources> <xcdg:DataGridCollectionViewSource x:Key="cvs_orders" Source="{Binding Source={x:Static Application.Current}, Path=Orders}" /> <Style TargetType="{x:Type xcdg:TableView}"> <Setter Property="IsAlternatingRowStyleEnabled" Value="True" /> </Style> </Grid.Resources> <xcdg:DataGridControl ItemsSource="{Binding Source={StaticResource cvs_orders}}" AutoCreateDetailConfigurations="True"> <xcdg:DataGridControl.DefaultDetailConfiguration> <xcdg:DefaultDetailConfiguration xcdg:TableView.IsAlternatingRowStyleEnabled="False"/> </xcdg:DataGridControl.DefaultDetailConfiguration> </xcdg:DataGridControl> </Grid> |